/*
 * User: ophir
 * Date: Sep 11, 2008
 * Time: 7:05:42 PM
 */
package org.conann.tests;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;

import javax.webbeans.Bean;
import java.util.Collection;

public class ComponentsContainImplClass extends BaseMatcher<Collection<Bean<?>>> {

    private final Class<?> impleClass;

    public ComponentsContainImplClass(Class<?> impleClass) {
        this.impleClass = impleClass;
    }

    @SuppressWarnings({"unchecked"})
    public boolean matches(Object components) {
        for (Bean<?> bean : ((Collection<Bean<?>>) components)) {
            if (bean.getImplClass().equals(impleClass)) {
                return true;
            }
        }
        return false;
    }

    public void describeTo(Description description) {
        description.appendText("Components list does not include a component which impl class is " + impleClass);
    }
}